<template>
  <div class="d_main">
    <!-- 操作区 S-->
    <na-table
      :datas.sync="tableData"
      :searchObj.sync="search"
      @updateDatas="getAllMaterils"
      @newAdd="selectCurrentRow"
    >
      <template #slot1>
        <el-button
          @click="isWrdialog = true"
          size="small"
          v-permission="'MenuCode2-5-1'"
          >预警物料({{ warringtotal }})</el-button
        >
      </template>
    </na-table>
    <!-- 人员寻找弹框   -->
    <per-redio-dialog
      :per-visible.sync="isperShow"
      @getEmployee="getEmployee"
    />
    <el-dialog
      :title="opstext + '采购'"
      :visible.sync="isAddProduct"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="85%"
      @close="closeDialog"
    >
      <div class="dialogDody">
        <div class="addWuliaoBox">
          <el-form
            ref="ProductForm"
            :model="ProductForm"
            :rules="rules"
            label-width="110px"
            label-position="left"
            class="dialogForm dialogInlineForm"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="采购单号" prop="purchaseOrderNo">
                  <el-input
                    v-model="ProductForm.purchaseOrderNo"
                    size="small"
                    disabled
                    placeholder="系统自动生成"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="创建日期" prop="purchaseOrderNo">
                  <el-input
                    :value="ProductForm.createDate || getDate()"
                    size="small"
                    placeholder="系统自动生成"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="创建人员"
                  prop="purchaseOrderNo"
                  v-if="ops === 'modify'"
                >
                  <el-input
                    v-model="ProductForm.createPersonName"
                    size="small"
                    placeholder="创建人员"
                    disabled
                  />
                </el-form-item>
                <el-form-item label="创建人员" prop="purchaseOrderNo" v-else>
                  <el-input :value="name" size="small" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="mb10">
              <el-col :span="8">
                <el-form-item label="采购类型" prop="getMaterialType">
                  <el-select
                        filterable
                    v-model="ProductForm.purchaseType"
                    placeholder="选择采购类型"
                    size="small"
                    :disabled="canDisablle"
                    filterable
                  >
                    <el-option
                      v-for="item in purchaseTypes"
                      :key="item.dicValueID"
                      :label="item.dicValueDesc"
                      :value="item.dicValueCode"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="供应商" prop="supplierCode">
                  <el-select
                        filterable
                    v-model="ProductForm.supplierCode"
                    placeholder="供应商"
                    size="small"
                    @change="handleSuplierChange"
                    clearable
                    filterable
                  >
                    <el-option
                      v-for="(item, index) in allSupliers"
                      :key="index"
                      :label="item.supplierName"
                      :value="item.supplierCode"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="期望到货时间">
                  <el-date-picker
                    v-model="ProductForm.expectArrivalTime"
                    type="date"
                    :picker-options="option"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                    size="small"
                    :disabled="canDisablle"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="采购备注" class="inlineText">
              <el-input
                v-model="ProductForm.purchaseDesc"
                type="textarea"
                :rows="3"
                placeholder="采购备注"
                size="small"
                clearable
                :disabled="canDisablle"
              />
            </el-form-item>
            <el-form-item
              label="拒绝原因"
              class="inlineText"
              v-if="ProductForm.inStockState == -1"
            >
              <el-input
                v-model="ProductForm.stockStateDesc"
                type="textarea"
                :rows="3"
                placeholder="拒绝原因"
                size="small"
                clearable
                :disabled="canDisablle"
              />
            </el-form-item>
          </el-form>
          <div class="tableBox">
            <div class="tt flex flex_between">
              <span class="fw">采购明细</span>
              <span
                v-show="!canDisablle"
                class="c_3F61F1 mr15 pointer"
                @click="showMateria = true"
                ><i class="el-icon-plus mr5" /> 新增</span
              >
            </div>
            <!-- <SelectMateriaList
              ref="materiaList"
              :per-visible.sync="showMateria"
              :select-list="ProductForm.mxDataList"
              @getMateriListData="refuseListsAll"
            /> -->
            <div ref="bigdialogTable" class="bigdialogTbCon">
              <el-table
                :data="ProductForm.mxDataList"
                border
                style="width: 100%"
              >
                <el-table-column type="index" label="序号" width="50" />
                <el-table-column
                  prop="stockGoodsCode"
                  width="150"
                  align="center"
                  label="物料编号"
                >
                  <template slot-scope="scope">
                    {{
                      !scope.row.stockGoodsCode
                        ? "选择后显示"
                        : scope.row.stockGoodsCode
                    }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="materialType"
                  width="150"
                  align="center"
                  label="物料类型"
                >
                  <template slot-scope="scope">
                    {{ scope.row.goodsType }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="school"
                  width="150"
                  align="center"
                  label="物料名称"
                >
                  <template slot-scope="scope">
                    <el-select
                        filterable
                      v-model="scope.row.goodsCode"
                      placeholder="请选择物料"
                      size="small"
                      @change="
                        handleMaterialNameChange(
                          scope.row,
                          scope.$index,
                          $event
                        )
                      "
                    >
                      <el-option
                        :label="item.goodsName"
                        :value="item.goodsCode"
                        v-for="(item, index) in materialList"
                        :key="index"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="specification"
                  width="150"
                  align="center"
                  label="规格型号"
                >
                  <template slot-scope="scope">
                    <el-select
                        filterable
                      v-model="scope.row.specification"
                      placeholder="请选择规格型号"
                      size="small"
                    >
                      <el-option
                        :label="item.specificationName"
                        :value="item.specificationCode"
                        v-for="(item, index) in scope.row
                          .goodsSpecificationList"
                        :key="index"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="goodsType"
                  width="150"
                  align="center"
                  label="物料类型"
                >
                  <template slot-scope="scope">
                    {{ scope.row.goodsType }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="stockQuantity"
                  width="150"
                  align="center"
                  label="库存数量"
                >
                </el-table-column>
                <el-table-column
                  prop="materialType"
                  width="150"
                  align="center"
                  label="入库数量"
                >
                </el-table-column>
                <el-table-column
                  prop="planPurchaseQuantity"
                  width="150"
                  align="center"
                  label="采购数量"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.planPurchaseQuantity"
                      size="small"
                    >
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="materialType"
                  width="150"
                  align="center"
                  label="使用单位"
                >
                </el-table-column>
                <el-table-column
                  prop="materialType"
                  width="150"
                  align="center"
                  label="转换比例"
                >
                </el-table-column>
                <el-table-column
                  prop="materialType"
                  width="150"
                  align="center"
                  label="计价单位"
                >
                </el-table-column>
                <el-table-column
                  prop="materialType"
                  width="150"
                  align="center"
                  label="单价"
                >
                </el-table-column>
                <el-table-column
                  prop="materialType"
                  width="150"
                  align="center"
                  label="小计"
                >
                </el-table-column>
                <el-table-column
                  prop="materialRemark"
                  align="center"
                  label="备注"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.materialRemark"
                      placeholder="请输入内容"
                      size="small"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="100px"
                  fixed="right"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-button
                      v-if="ProductForm.mxDataList.length - 1 != scope.$index"
                      type="text"
                      @click="handleCopyRow(scope.row, scope.$index)"
                      >复制</el-button
                    >
                    <el-button
                      type="text"
                      v-if="ProductForm.mxDataList.length - 1 != scope.$index"
                      @click="handleDeleteRow(scope.row, scope.$index)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="isAddProduct = false">取 消</el-button>
        <!-- 新增       -->
        <el-button
          v-show="!canDisablle"
          v-loading="addProductLoading"
          :disabled="addProductLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="small"
          @click="saveOrder"
          >保存</el-button
        >
      </div>
    </el-dialog>
    <!-- 预警物料      -->
    <el-dialog
      append-to-body
      title="预警物料"
      :visible.sync="isWrdialog"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="70%"
      @close="isWrdialog = false"
      @open="getWarningList"
    >
      <div class="dialogDody marDialog flex flex_column">
        <div class="btnCon flex flex_between">
          <div>
            <el-button
              v-loading="addLoading"
              :disabled="addLoading"
              element-loading-spinner="el-icon-loading"
              type="primary"
              size="small"
              icon="el-icon-plus"
              @click="saveColorManuscript"
            >
              新建采购</el-button
            >
          </div>
          <!--      搜索框-->
          <div class="search">
            <el-input
              v-model="SemiSearch.likeWords"
              placeholder="输入关键字"
              size="small"
            >
              <el-button
                slot="append"
                v-loading="WarLoading"
                type="primary"
                icon="el-icon-search"
                :disabled="WarLoading"
                element-loading-spinner="el-icon-loading"
                @click="getWarningList"
              >
                搜索
              </el-button>
            </el-input>
          </div>
        </div>
        <!-- 表格区域       -->
        <div class="tableCon not">
          <el-table
            :data="WarningList"
            border
            style="width: 100%"
            height="400"
            @selection-change="handleSelectionChange"
          >
            <el-table-column prop="selection" width="55">
              <el-table-column type="selection" width="55" />
              <el-table-column prop="stockGoodsCode" label="物料编号" />
              <el-table-column prop="goodsName" label="物料名称" />
              <el-table-column prop="stockGoodsName" label="规格型号" />
              <el-table-column
                prop="supplierName"
                label="供应商"
                width="200"
                show-overflow-tooltip
              />
              <el-table-column prop="categoryName" label="物料类型" />
              <el-table-column prop="stockQuantity" label="库存数量" />
              <el-table-column prop="unitName" label="单位" />
              <el-table-column
                prop="groupName"
                label="所属分组"
              /> </el-table-column
          ></el-table>
        </div>
      </div>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="isMarterdialog = false">取 消</el-button>
        <el-button
          v-loading="addLoading"
          :disabled="addLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="small"
          @click="saveColorManuscript"
        >
          确定</el-button>
      </div> -->
    </el-dialog>

    <!-- 原因   -->
    <el-dialog
      title="作废原因"
      :visible.sync="isNopassshow"
      :close-on-click-modal="false"
      custom-class="comDialog"
      width="40%"
      @close="closePassDialog"
    >
      <div class="dialogDody">
        <el-form ref="passForm" :model="passForm" class="dialogForm">
          <el-form-item class="mt12">
            <el-input
              v-model="passForm.cancelReason"
              prop="cancelReason"
              type="textarea"
              placeholder="请输入内容"
              :autosize="{ minRows: 6 }"
              size="small"
            />
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="isNopassshow = false">取 消</el-button>
        <el-button
          :disabled="addLoading"
          element-loading-spinner="el-icon-loading"
          type="primary"
          size="small"
          @click="passSave"
          >提交</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { arraySort } from "@/utils";
import HeadSeting from "@/components/HeadSeting";
import Pagination from "@/components/Pagination";
import perRedioDialog from "@/components/perDialogRedio";
import SelectMateriaList from "@/components/selectMaterial";
import screec from "@/components/screen";
import { mapGetters } from "vuex";
import naTable from "@/components/naTable";

export default {
  name: "Materiel",
  components: {
    Pagination,
    HeadSeting,
    perRedioDialog,
    SelectMateriaList,
    screec,
    naTable,
  },
  data() {
    return {
      isWrdialog: false,
      WarLoading: false,
      ops: "add", // 操作、新建，修改，查看
      tableHeight: null, // 表格最大高度
      showOrder: false,
      isSeeMaterriel: false, // 查看弹框是否打开
      isAddMaterriel: false, // 新建弹框是否打开
      addMaterrielLoading: false, // 新建保存加载
      searchLoading: false, // 搜索加载效果
      allMaterirls: [], // 全部数据列表
      colorState: null,
      // 表格操作
      ProductForm: {
        purchaseType: "",
        organizationCode: "",
        departmentCode: "",
        purchasePersonCode: "",
        expectArrivalTime: "",
        purchaseDesc: "",
        mxDataList: [],
      },
      passForm: {
        cancelReason: "",
      },
      currItem: null,
      // 搜索条件
      search: {
        QueryDataBaseFiled: "",
        pageIndex: 1,
        pageSize: 30,
        likeWords: "",
      },

      tableData: {
        headId: "head", //表头列显隐组件所需ID-避免多个页面id重复问题
        tableId: "purchaseID", //表格列表key,也就是一条数据的唯一标识
        senior: false, //高级搜索是否显示
        addPermission: "MenuCode2-5-1", //新建按钮权限
        disableWord: "", //是否禁用显示的字段
        disableStatus: "", //判断未禁用的状态值
        //表格按钮
        operationBtn: [
          {
            title: "查看",
            methodsName: "handleClick",
          },
          {
            title: "编辑",
            methodsName: "handleUpdata",
            permission: "MenuCode2-3-2-2",
            hideCondition: {
              //按钮显隐条件
              prop: "getProductBillState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用
                0,
              ],
            },
          },
          {
            title: "作废",
            methodsName: "handleDone",
            permission: "MenuCode2-5-2",
            hideCondition: {
              //按钮显隐条件
              prop: "inStockState", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用
                0,
              ],
            },
          },
          {
            title: "复制",
            methodsName: "handleCopy",
            permission: "MenuCode2-5-3",
            hideCondition: {
              //按钮显隐条件
              prop: "isCopy", //控制显隐的状态字段
              show: [
                //有哪些状态可以使用
                1,
              ],
            },
          },
        ],
        //表格内容
        tbody: [],
        //表格表头
        thead: [],
      },

      total: 0, // 总条数
      tableHead: [], // 表格表头
      addProductLoading: false,
      isAddProduct: false,
      isperShow: false,
      isSemidialog: false,
      warringtotal: 0,
      purchaseInfoDatas: [{}],
      allSupliers: [],
      purchaseTypes: [], // 采购类型
      WarningList: [], // 物料预警
      showMateria: false,
      opstext: "",
      canDisablle: false,
      isNopassshow: false,
      multipleSelection: [],
      option: {
        disabledDate: (time) => {
          return time.getTime() < Date.now() - 1 * 24 * 3600 * 1000;
        },
      },
      selectRow: null,
      SemiSearch: {
        likeWords: "",
      },
      materialList: [],
      allSupliers: [], //供应商
      marLoading: false,
      addLoading: false,

      rules: {
        purchaseType: [
          { required: true, message: "请选择采购类型", trigger: "change" },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["name", "userInfo"]),
  },
  created() {
    this.ProductForm.purchasePersonCode = this.userInfo.employeeCode;
    this.ProductForm.purchasePersonName = this.userInfo.employeeName;
    //  所有列表数据
    this.getAllMaterils();
    // 表格得表头
    this.getTableHead();

    this.getPurchaseType();

    this.getWarningList();

    //获取物料下拉
    // this.getmaterialList();

    //获取供应商
    this.getSupplier();
  },
  mounted() {},
  updated() {},
  methods: {
    // 作废
    closePassDialog() {
      this.passForm.cancelReason = "";
      this.selectRow = null;
    },
    passSave(item) {
      const _data = {
        purchaseID: this.selectRow.purchaseID,
        cancelReason: this.passForm.cancelReason,
      };
      this.$api.product
        .CancelPurchaseOrder(_data)
        .then((res) => {
          this.$message({
            message: "成功",
            type: "success",
          });
          this.getAllMaterils();
          this.isNopassshow = false;
        })
        .catch(() => {
          this.isNopassshow = false;
        });
    },
    handleDone(item) {
      this.selectRow = item;
      this.isNopassshow = true;
    },

     //删除
     handleDeleteRow(row, index) {
      this.ProductForm.mxDataList.splice(index, 1);
    },

    //复制
    handleCopyRow(row, index) {
      this.ProductForm.mxDataList.splice(
        index,
        0,
        JSON.parse(JSON.stringify(row))
      );
      this.$forceUpdate()
    },
    // 复制
    handleCopy(row) {
      this.opstext = "复制";
      this.canDisablle = false;
      const parmas = {
        purchaseID: row.purchaseID,
      };
      this.$api.product
        .GetPurchaseOrderDetail(parmas)
        .then((res) => {
          this.isAddProduct = true;
          this.ProductForm = res.baseData;
          this.ProductForm.mxDataList = res.mxDataList;
          delete this.ProductForm.purchaseOrderNo;
        })
        .catch(() => {
          this.addMaterrielLoading = false;
        });
    },

    // 供应商
    getSupplier() {
      this.$api.mater.GetAllSuppliers().then((res) => {
        this.allSupliers = res;
      });
    },

    //供应商选择事件
    handleSuplierChange(e) {
      this.$api.mater
        .GetGoodsSpecificationBySupplierCode({
          queryBy: 0,
          queryValue: e,
        })
        .then((res) => {
          this.materialList = res;
        });
    },

    //物料下拉选择事件
    handleMaterialNameChange(row, index, e) {
      console.log(row);
      if (index == this.ProductForm.mxDataList.length - 1) {
        this.ProductForm.mxDataList.push({
          supplierCode: "",
          stockGoodsCode: "",
          planPurchaseQuantity: 0,
          purchaseDesc: "",
        });
      }
      this.materialList[index].stockGoodsCode = e;
      this.materialList.forEach((item, i) => {
        if (item.goodsCode == e) {
          row.materialType = item.categoryName;
          row.materialName = item.goodsName;
          row.goodsSpecificationList = item.goodsSpecificationList;
        }
      });
      // row.productMaterialCode = e.goodsCode;
      // row.materialType = e.categoryName;
      // row.materialName = e.goodsName;
      // this.getStockGoodsList(e);
    },
    // 新增物料
    // refuseListsAll(val) {
    //   val.forEach((res) => {
    //     if (res.stockSumQuantity) {
    //       res.stockQuantity = res.stockSumQuantity;
    //     }
    //     const checked = this.ProductForm.mxDataList.some(
    //       (item) => item.stockGoodsCode === res.stockGoodsCode
    //     );
    //     if (checked) {
    //     } else {
    //       this.ProductForm.mxDataList.push(res);
    //     }
    //   });
    // },

    getDate() {
      return this.dayjs().format("YYYY-MM-DD");
    },
    // 删除物料
    deleteRow(index) {
      this.$confirm("确定删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.ProductForm.mxDataList.splice(index, 1);
      });
    },
    // 预警物料
    getWarningList() {
      this.$api.product
        .GetMatchWarningStockGoodsDataList(this.SemiSearch)
        .then((res) => {
          this.WarningList = res;
          this.warringtotal = res ? res.length : 0;
        })
        .catch(() => {
          this.addMaterrielLoading = false;
        });
    },

    //获取物料下拉
    getmaterialList() {
      const parmas = {
        pageIndex: 1,
        pageSize: 9999,
        queryDataBaseFiled: "",
        likeWords: "",
        isShowDisabled: 0,
        groupCode: "",
        categoryCode: "",
        goodsCode: "",
        unitCode: "",
        isDisable: 0,
        isDelete: 0,
      };
      this.$api.business
        .GetMatchPageGoods(parmas)
        .then((res) => {
          this.materialList = res.list;
          // this.ProductForm.mxDataList.forEach((x) => {
          //   this.materialList.forEach((item) => {
          //     if (x.stockGoodsCode == item.goodsCode) {
          //       x.list = item.list;
          //     }
          //   });
          // });
          console.log(this.formData.productMaterialList);
        })
        .catch(() => {});
    },
    // 类型
    getPurchaseType() {
      const parmas = {
        pageIndex: 1,
        pageSize: 100,
        likeWords: "",
        dictionaryCode: "PurchaseType",
        dicValueState: 1,
      };
      this.$api.system
        .QueryPageDictionaryValueDataList(parmas)
        .then((res) => {
          this.purchaseTypes = res.list;
        })
        .catch(() => {
          this.addMaterrielLoading = false;
        });
    },
    getWrList() {},
    handleClick(row) {
      this.ops = "modify";
      this.opstext = "查看";
      this.canDisablle = true;
      const parmas = {
        purchaseID: row.purchaseID,
      };
      this.$api.product
        .GetPurchaseOrderDetail(parmas)
        .then((res) => {
          this.isAddProduct = true;
          this.ProductForm = res.baseData;
          this.ProductForm.mxDataList = res.mxDataList;
        })
        .catch(() => {
          this.addMaterrielLoading = false;
        });
    },
    selectCurrentRow() {
      this.ops = "add";
      this.opstext = "新建";
      this.canDisablle = false;
      this.isAddProduct = true;
      this.ProductForm.mxDataList.push({
        supplierCode: "",
        stockGoodsCode: "",
        planPurchaseQuantity: 0,
        purchaseDesc: "",
      });
    },
    // 新建点击事件
    newAddClick() {
      this.ops = "add";
      this.opstext = "新建";
      this.isAddProduct = true;
    },
    //  修改班次
    modifyInfo(data) {
      this.ProductForm = Object.assign(data, {});
    },
    // 得到申请人员
    getEmployee(val) {
      this.ProductForm.organizationCode = val.organizationCode;
      this.ProductForm.departmentCode = val.departmentCode;
      this.ProductForm.purchasePersonCode = val.employeeCode;
      this.ProductForm.purchasePersonName = val.employeeName;
    },
    supplierChange(val) {
      this.materSearch.supplierCode = val;
      this.purchaseInfoDatas = [];
    },
    closeSemiDialog() {
      this.isSemidialog = false;
    },
    MarterdialogShow() {},
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    saveColorManuscript() {
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach((item) => {
          item.goodsUnitName = item.unitName;
        });
        this.isAddProduct = true;
        this.canDisablle = false;

        // this.refuseListsAll(this.multipleSelection);
      } else {
        this.$message({
          message: "请选择预警物料",
          type: "error",
        });
      }
    },
    // 新建保存
    saveOrder() {
      const _mxArr = this.ProductForm.mxDataList;
      for (let index = 0; index < _mxArr.length; index++) {
        if (!_mxArr[index].planPurchaseQuantity) {
          this.$message({
            message: "有没填写的采购数量",
            type: "warning",
          });
          return;
        }
      }
      this.$confirm("本单有多个供应商,保存后自动按照供应商物料拆分?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product
          .CreatePurchaseOrder(this.ProductForm)
          .then((res) => {
            this.getAllMaterils();
            this.isAddProduct = false;
            this.$message({
              message: "保存成功",
              type: "success",
            });
          })
          .catch(() => {
            this.isAddProduct = false;
          });
      });
    },
    // 保存表头样式变化
    saveHead(newArray) {
      const parmas = newArray;
      setTimeout(() => {
        this.$api.common.saveTableStyle(parmas).then(() => {});
      }, 300);
    },
    // 保存表头列宽度
    surverWidth(newWidth, oldWidth, column) {
      setTimeout(() => {
        const heads = [...this.tableHead];
        heads.forEach((item) => {
          if (item.columnCode === column.property) {
            item.columnWidth = column.width;
            return;
          }
        });
        this.saveHead(heads);
      }, 100);
    },
    // ，清除所有查询条件
    Refresh() {
      this.search = this.$options.data().search;
      this.getAllMaterils();
    },
    // 获取表格表头
    getTableHead() {
      const parmas = {
        tableCode: this.$config.applypurchaseorderlist,
      };
      this.$api.common.getAllTableHead(parmas).then((res) => {
        res.sort(arraySort("columnSort"));
        this.tableData.thead = res;
      });
    },
    // 所有列表数据
    getAllMaterils() {
      const parmas = this.search;
      this.searchLoading = true;
      this.$api.product
        .GetMatchPagePurchaseOrders(parmas)
        .then((res) => {
          this.allMaterirls = res.list;
          this.tableData.tbody = res.list;
          this.search.total = res.totalCount;
          this.allMaterirls.forEach((item) => {
            item.isCopy = 0;
            if (item.purchaseOrderState === -1 || item.inStockState === -1) {
              item.isCopy = 1;
            }
            for (let i in item) {
              if (!item[i] && item[i] !== 0) {
                item[i] = "--";
              }
            }
          });
          this.total = res.totalCount;
          this.searchLoading = false;
        })
        .catch(() => {
          this.searchLoading = false;
        });
    },
    // 新建弹框关闭事件
    closeDialog() {
      if (this.$refs.ProductForm) {
        this.$refs.ProductForm.resetFields();
      }
      this.ProductForm = this.$options.data().ProductForm;
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  height: 100%;
}
.permangeRg {
  border: 1px solid #e6e6e6;
  background: #fff;
  height: 100%;

  .mainTT {
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    padding: 18px 16px;
    padding-bottom: 0;
  }
}
.addWuliaoBox {
  padding: 10px 16px;

  .tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;

    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
  }
}

.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}
</style>
